package com.sise.dubbo.controller;

import com.sise.dubbo.common.ServiceException;
import com.sise.dubbo.model.User;
import com.sise.dubbo.service.UserService;
import com.sise.dubbo.vo.PageRespVo;
import com.sise.dubbo.vo.WsResponseMsgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hao_lin
 * @data 2018/9/29 13:48
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/test")
    public String printStr() {
        return userService.print("hhah");
    }

    @GetMapping(value = "/findAll")
    public WsResponseMsgVO<PageRespVo<User>> findAll(int page) {
        return WsResponseMsgVO.builderSuccessRespData(userService.findAll(page));
    }

    @GetMapping(value = "/findByUsername")
    public WsResponseMsgVO<PageRespVo<User>> findByUsername(String username,int page) throws ServiceException {
        return WsResponseMsgVO.builderSuccessRespData(userService.findByUsername(username, page));
    }
}
